package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author dxt
 * @create 2025-07-16-11:47
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 分页查询供应商
     * @param page
     * @param rows
     * @param supplierName
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> list(Integer page, Integer rows, String supplierName) {
        return supplierService.list(page, rows, supplierName);
    }

    /**
     * 新增或修改供应商
     * @param supplierId
     * @param supplier
     * @return
     */
    @PostMapping("/save")
    public ServiceVO saveOrUpdate(@RequestParam(value = "supplierId", required = false) Integer supplierId, @ModelAttribute Supplier supplier) {
        supplierService.saveOrUpdate(supplierId, supplier);
        return new ServiceVO(100, "操作成功", null);
    }

    /**
     * 删除供应商
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(String ids) {
        supplierService.delete(ids);
        return new ServiceVO(100, "操作成功", null);
    }

    /**
     * 下拉列表查询供应商
     * @param q 供应商名称模糊查询
     * @return
     */
    @PostMapping("/getComboboxList")
    public List<Supplier> getComboboxList(String q) {
        List<Supplier> supplierList = supplierService.getComboboxList(q);
        return supplierList;
    }
}
